package com.meida.student.app.user.handler;

import com.meida.common.base.entity.EntityMap;
import com.meida.common.mybatis.interceptor.GetInterceptor;
import com.meida.common.mybatis.query.CriteriaQuery;
import com.meida.module.user.client.entity.AppSchool;
import com.meida.module.user.client.entity.AppUser;
import com.meida.module.user.provider.service.AppAccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 用户详情
 *
 * @author zyf
 */
@Component
public class UserMineInfoHandler implements GetInterceptor {

    @Autowired
    private AppAccountService appAccountService;

    @Override
    public void prepare(CriteriaQuery cq, EntityMap entityMap) {
        cq.select(AppUser.class, "*");
        cq.select(AppSchool.class, "schoolName", "isOpen");
        cq.createJoin(AppSchool.class).setMainField("schoolId").setJoinField("schoolId");
    }

    @Override
    public void complete(CriteriaQuery cq, EntityMap map) {
        Long userId = map.getLong("userId");
        Boolean isBindWeixin = appAccountService.isExist(userId, "WEIXIN");
        map.put("isBindWeixin", isBindWeixin);
        Boolean isBindApple = appAccountService.isExist(userId, "QQ");
        map.put("isBindApple", isBindApple);
    }
}
